Scroll Progress Bar

Data Types

C++ provides a variety of data types that allow to store different kinds of data, such as integers, floating-point numbers, characters, and more. These data types are categorized into three main groups: basic data types, derived data types, and defined data types. Here's an overview of some of the common data types in C++:

Basic Data Types:
Integer Types:
  • int: Represents signed integers.
  • unsigned int: Represents unsigned (non-negative) integers.
  • short: Represents short integers.
  • long: Represents long integers.
  • long long: Represents very long integers (introduced in C++11).
Floating-Point Types:
  • float: Represents single-precision floating-point numbers.
  • double: Represents double-precision floating-point numbers (most commonly used for floating-point calculations).
  • long double: Represents extended-precision floating-point numbers.
Character Types:
  • char: Represents a single character.
  • wchar_t: Represents a wide character (used for extended character sets).
  • char16_t and char32_t: Introduced in C++11, used for Unicode character representation.
Boolean Type:

bool: Represents a boolean value, which can be either true or false.

Derived Data Types:

Array Types: Arrays allow to store multiple elements of the same data type in a contiguous memory block.

Program:

int myArray[5]; // Declares an array of 5 integers

Pointer Types: Pointers store memory addresses, allowing to work with dynamic memory allocation and direct memory access.

Program:

int* ptr; // Declares a pointer to an integer

Reference Types: References provide an alias for an existing variable. They are often used as function parameters.

Program:

int x = 10;
int& ref = x; // Declares a reference to the integer variable x

Structures (struct): Structures allow to create custom data types composed of multiple variables of different data types.

Program:

struct Point {
    int x;
    int y;
};

Classes: Classes are similar to structures but also include member functions and can be used for object-oriented programming.

Program:

class Rectangle {
public:
    int width;
    int height;
    int area() { return width * height; }
};

Enumerations (enum): Enumerations define a set of named integer constants.

Program:

enum Color { Red, Green, Blue };
Color selectedColor = Green;

Typedefs (typedef): Typedefs allow to create aliases for existing data types, making code more readable.

Program:

typedef unsigned long long ull;
ull bigNumber = 1000000000ULL;

These are some of the fundamental data types in C++. Depending on specific needs, can choose the appropriate data type to store and manipulate data efficiently. Additionally, C++ allows creating defined data types using classes and structures, providing flexibility in data modeling and abstraction.


question


answer

question2


answer2